using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Shop_Member_Shop_RePayOrder : Member, IRequiresSessionState
{
	protected Label LabCusName;
	protected Label LabOrderNum;
	protected Label LabTotalMoney;
	protected Label LabPayedMoney;
	protected TextBox ReceiptDate;
	protected TextBox TxtPoundage;
	protected RangeValidator Rav2;
	protected RequiredFieldValidator Req3;
	protected ScriptManager ScriptManager1;
	protected TextBox Money;
	protected RangeValidator Rav1;
	protected RequiredFieldValidator Req1;
	protected UpdatePanel UpdatePanel1;
	protected RadioButtonList RadioButtonList1;
	protected HtmlInputText Remark;
	protected CheckBox CheckSendMobileMesToCus;
	protected CheckBox CheckSendMobileMesToRe;
	protected CheckBox CheckSendMesMesToCus;
	protected CheckBox CheckSendEmailMesToCus;
	protected CheckBox CheckSendEmailMesToRe;
	protected Button Button1;
	protected Button Button2;
	public static string UserName = "";
	public static string SalerName = "";
	public static string UserTureName = "";
	public static string SalerTureName = "";
	public static int OrderFormID = 0;
	public static string OrderFormNum = "";
	public static int UserID = 0;
	public static int SalerID = 0;
	public static decimal MoneyTotal = 0m;
	public static decimal MoneyReceipt;
	public static string Email = "";
	public static string UserEmail = "";
	public static string SalerEmail = "";
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (base.Request["OrderFormNum"] == null)
		{
			base.Response.Write("没有应答的订单或者订单已经出局");
			base.Response.End();
		}
		else
		{
			Shop_Member_Shop_RePayOrder.OrderFormNum = base.Request["OrderFormNum"].ToString();
		}
		if (!base.IsPostBack)
		{
			if (base.Request.UrlReferrer != null)
			{
				this.ViewState["UrlReferrer"] = base.Request.UrlReferrer.ToString();
			}
			this.ReceiptDate.Text = DateTime.Now.ToShortDateString();
			Shop_Order shop_Order = new Shop_Order();
			DataTable orderByOrderFormNum = shop_Order.GetOrderByOrderFormNum(Shop_Member_Shop_RePayOrder.OrderFormNum);
			if (orderByOrderFormNum.Rows.Count <= 0)
			{
				base.Response.Write("没有应答的订单或者订单已经出局");
				base.Response.End();
			}
			else
			{
				Shop_Member_Shop_RePayOrder.OrderFormID = int.Parse(orderByOrderFormNum.Rows[0]["OrderFormID"].ToString());
				Shop_Member_Shop_RePayOrder.UserID = int.Parse(orderByOrderFormNum.Rows[0]["UserID"].ToString());
				Shop_Member_Shop_RePayOrder.SalerID = int.Parse(orderByOrderFormNum.Rows[0]["SalerID"].ToString());
				this.LabOrderNum.Text = orderByOrderFormNum.Rows[0]["OrderFormNum"].ToString();
				this.LabPayedMoney.Text = orderByOrderFormNum.Rows[0]["MoneyReceipt"].ToString();
				this.LabTotalMoney.Text = orderByOrderFormNum.Rows[0]["MoneyTotal"].ToString();
				this.Money.Text = this.LabPayedMoney.Text;
				Shop_Member_Shop_RePayOrder.Email = orderByOrderFormNum.Rows[0]["Email"].ToString();
				UserBll userBll = new UserBll(this.conn);
				UserInfoBll userInfoBll = new UserInfoBll(this.conn);
				DataTable userByUserID = userBll.GetUserByUserID(Shop_Member_Shop_RePayOrder.UserID);
				DataTable userByUserID2 = userBll.GetUserByUserID(Shop_Member_Shop_RePayOrder.SalerID);
				DataTable userInfoByUserID = userInfoBll.GetUserInfoByUserID(Shop_Member_Shop_RePayOrder.UserID);
				DataTable userInfoByUserID2 = userInfoBll.GetUserInfoByUserID(Shop_Member_Shop_RePayOrder.SalerID);
				try
				{
					this.LabCusName.Text = userInfoByUserID.Rows[0]["TrueName"].ToString();
					Shop_Member_Shop_RePayOrder.UserEmail = userByUserID.Rows[0]["Email"].ToString();
					Shop_Member_Shop_RePayOrder.UserTureName = userInfoByUserID.Rows[0]["TrueName"].ToString();
					Shop_Member_Shop_RePayOrder.SalerTureName = userInfoByUserID2.Rows[0]["TrueName"].ToString();
					Shop_Member_Shop_RePayOrder.UserName = userByUserID.Rows[0]["UserName"].ToString();
					Shop_Member_Shop_RePayOrder.SalerName = userByUserID2.Rows[0]["UserName"].ToString();
					Shop_Member_Shop_RePayOrder.SalerEmail = userByUserID2.Rows[0]["Email"].ToString();
				}
				catch
				{
				}
				this.Remark.Value = "订单退款金额，订单号：" + Shop_Member_Shop_RePayOrder.OrderFormNum.ToString();
				if (Shop_Member_Shop_RePayOrder.SalerID.ToString().Trim() != base.user.UserID.ToString().Trim())
				{
					base.Response.Write("你没权限操作此数据");
					base.Response.End();
				}
			}
		}
	}
	protected void Button1_Click(object sender, EventArgs e)
	{
		if (base.IsValid)
		{
			decimal num = decimal.Parse(this.Money.Text);
			if (decimal.Parse(this.LabPayedMoney.Text) < decimal.Parse(this.TxtPoundage.Text) + num)
			{
				this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert('退款不能大于已付款！')</script>");
			}
			else
			{
				UserBll userBll = new UserBll(this.conn);
				Shop_BankrollItem shop_BankrollItem = new Shop_BankrollItem();
				int moneyType = 3;
				if (this.RadioButtonList1.SelectedIndex != 0)
				{
					moneyType = 4;
				}
				Shop_Order shop_Order = new Shop_Order();
				if (shop_Order.updateStatus(Shop_Member_Shop_RePayOrder.OrderFormNum, "-1", "", ""))
				{
					if (shop_BankrollItem.AddBankrollItem(Shop_Member_Shop_RePayOrder.UserID, Shop_Member_Shop_RePayOrder.SalerID, num, moneyType, 0, 0, 0, 1, Shop_Member_Shop_RePayOrder.OrderFormID, 0, this.Remark.Value, "卖家已经确认"))
					{
						this.SendMsgEmail();
					}
					else
					{
						this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert('退款成功，退款记录添加失败！请联系管理员')</script>", false);
					}
				}
				else
				{
					this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert('退款成功，订单修改失败！请联系管理员')</script>", false);
				}
			}
		}
	}
	protected void Button2_Click(object sender, EventArgs e)
	{
		if (base.Request.UrlReferrer != null)
		{
			base.Response.Redirect(this.ViewState["UrlReferrer"].ToString());
		}
	}
	protected void TxtPoundage_TextChanged(object sender, EventArgs e)
	{
	}
	protected void SendMsgEmail()
	{
		string text = "";
		Text text2 = new Text();
		if (this.CheckSendMesMesToCus.Checked)
		{
			MessageBll messageBll = new MessageBll(this.conn);
			if (messageBll.AddMessage(Shop_Member_Shop_RePayOrder.SalerName, "Users", "你的订单已经退款", string.Concat(new string[]
			{
				"尊敬的",
				Shop_Member_Shop_RePayOrder.UserTureName,
				":\n你的订单:",
				Shop_Member_Shop_RePayOrder.OrderFormNum,
				"已经退款",
				this.Money.Text,
				"元，扣除手续费",
				this.TxtPoundage.Text,
				"元，敬请及时关注\n这是是系统信息，请勿回复"
			}), 0, 0, 1, 0, Shop_Member_Shop_RePayOrder.UserName, "", 1))
			{
				text = " 已向用户发送站内信通知订单已经退款";
			}
		}
		if (this.CheckSendEmailMesToCus.Checked || this.CheckSendEmailMesToRe.Checked)
		{
			string str = this.config["SiteName"].ToString();
			string smtpserver = this.config["MailSmtpServer"].ToString();
			string mailuser = this.config["MailServerUserName"].ToString();
			string mailpassword = this.config["MailServerPassWord"].ToString();
			string mailFrom = this.config["MailServerFrom"].ToString();
			if (this.CheckSendEmailMesToCus.Checked)
			{
				try
				{
					string mailTitle = str + "退款邮件";
					string text3 = this.config["MessageOfRefund"].ToString();
					text3 = text3.Replace("{$UserName$}", Shop_Member_Shop_RePayOrder.UserTureName);
					text3 = text3.Replace("{$InputTime$}", DateTime.Now.ToString());
					text3 = text3.Replace("{$OrderFormNum$}", Shop_Member_Shop_RePayOrder.OrderFormNum);
					text3 = text3.Replace("{$OrderInfo$}", "");
					Email email = new Email();
					email.SendEmail(smtpserver, mailuser, mailpassword, mailFrom, text3, Shop_Member_Shop_RePayOrder.UserEmail, mailTitle);
					text += " 已向用户发送Email通知订单已经退款";
				}
				catch
				{
				}
			}
			if (this.CheckSendEmailMesToRe.Checked)
			{
				try
				{
					string mailTitle = str + "退款邮件";
					string text3 = this.config["MessageOfRefund"].ToString();
					text3 = text3.Replace("{$UserName$}", Shop_Member_Shop_RePayOrder.UserTureName);
					text3 = text3.Replace("{$InputTime$}", DateTime.Now.ToString());
					text3 = text3.Replace("{$OrderFormNum$}", Shop_Member_Shop_RePayOrder.OrderFormNum);
					text3 = text3.Replace("{$OrderInfo$}", string.Concat(new string[]
					{
						"已经退款",
						this.Money.Text,
						"元，扣除手续费",
						this.TxtPoundage.Text,
						"元，敬请及时关注\n这是是系统信息，请勿回复"
					}));
					Email email = new Email();
					email.SendEmail(smtpserver, mailuser, mailpassword, mailFrom, text3, Shop_Member_Shop_RePayOrder.Email, mailTitle);
					text += " 已向收货人发送Email通知订单已经退款";
				}
				catch
				{
				}
			}
		}
		this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", string.Concat(new string[]
		{
			"<script>alert('",
			text,
			"');location.href='Shop_BuyOrder.aspx?OrderFormNum=",
			Shop_Member_Shop_RePayOrder.OrderFormNum,
			"';</script>"
		}));
	}
}
